﻿package net
{
	import config.DConfig;
	
	import flash.events.EventDispatcher;
	import flash.net.NetStream;
	import flash.utils.ByteArray;
	
	import net.event.DNetworkGameEvent;
	
	/**
	* ...
	* @author cuiwei
	*/
	public class DNetworkGame extends EventDispatcher
	{
		//STA########################################################################################
		private const CMD_REQUEST_LOGIN:String = "RQLG";						//请求登陆
		static public const CMD_LOGIN_RESULT:String = "RELG";					//登陆结果
		
		static public const CMD_MY_INFO:String = "MYINFO";						//收到自己信息
		static public const CMD_ENTER_ROOM:String = "ENTG";						//进入游戏		
		static public const CMD_ROOM_LIST:String = "TJDROOM";					//房间列表
		static public const CMD_BACK_TO_HALL:String = "TJBACKROOM";
		static public const CMD_ROOM_PEOPLE_NUM:String = "TJDRMNUM";			//房間人數
		//END########################################################################################
		
		
		
		private const CMD_REQUEST_ROOMLIST_PAGE:String = "RQDP";   		//请求分页桌子详细信息
		private const CMD_REQUEST_DESKLIST:String = "RQFD";	   			//请求分页桌子详细信息
		private const CMD_REQUEST_STANDUP:String = "RQSU";				//用户站起
		private const CMD_REQUEST_CHANGE_FACE:String = "RQCF";			//用户申请改变头像
		private const CMD_REQUEST_ACTIVE_FACE:String = "RAAF";			//用户申请激活头像
		private const CMD_REQUEST_TIME_TIME:String = "RETT";			//心跳
		private const CMD_REQUEST_ONLONE_SERVER:String = "RQOS";		//查询所有服务器的在线人数
		private const CMD_REQUEST_GIVE_GOLD:String = "RQGG";			//要求送钱
		private const CMD_REQUEST_CLIENT_LEAVE_ROOM:String = "RQCLR";   //离开牌桌大厅
		
		private const CMD_REQUEST_UPDATE_GOLD:String = "RQGB";			//要求服务器刷新钱
		private const CMD_REQUEST_WATCH:String = "REWT";				//要求观战
		private const CMD_REQUEST_EXIT_WATCH:String = "REET";			//要求退出观战
		private const CMD_REQUEST_ROOM_SORT_LIST:String = "RQRSL";		//客户端请求房间玩家排名
		private const CMD_REQUEST_UPDATE_VIPINFO:String = "RQVIPIF";	//客户端请求刷新VIP信息
		private const CMD_NOTIFY_TEX_BBS_URL:String 	= "TXNBBS";		//收到论坛验证码
		private const CMD_RECV_REFRESH_PROPS_COUNT:String 	= "TXREDJNUM";	//收到更新游戏道具数量
		//-------------------------特权码str--------------------
		private const  CMD_NOTIFY_TEX_PRIVILEGE_YANZHENG:String = "JHMGIFTSN"//特权码验证
		//-------------------------特权码end--------------------
		private const CMD_TEX_UPDATE_CHANNEL_INFO:String = "TEXUSERCHANNEL";	//更新用户昵称
		private const CMD_TEX_CHOOSE_ROLE:String = "TEXAUTHORBAR";				//收到显示选择角色面板		
		private const CMD_TEX_UPDATE_NICK_INFO:String = "TEXUSERNICK";	//更新用户昵称
		//------------喇叭start---------------------
		private const CMD_TEX_SPEAKER_BROADCAST:String = "SPEAKERBC";//请求广播
		private const CMD_TEX_SPEAKER_NUM:String = "SPEAKERNUM";       //喇叭剩余次数
		//------------喇叭end---------------------
		
		//------------异地上线保护start---------------------
		private const CMD_TEX_CHECK_IP:String = "TXCHECKIP";//异地上线保护
		private const CMD_TEX_UNLOCK:String = "TXUNLOCK";//解锁
		//private const CMD_TEX_FIRST_PROTECTION:String = "TXPROTECTION"; //是否第一次设置登录保护
		//------------异地上线保护end---------------------
		
		//------------游戏设置start-----------------------
		private const CMD_TEX_TXPERSZ:String = "TXPERSZ";//个人设置
		//private const CMD_TEX_TXPAYSZ:String = "TXPAYSZ";//牌样设置
		//------------游戏设置end-----------------------
		//接受的命令(响应)
		
	
		private const CMD_RESPONSE_DESK_USERLIST:String = "SDDU";      		//取得桌子里玩家的详细信息
		
	  	private const CMD_RESPONSE_ROOMLIST_DESK_CHANGED:String = "SDDSS";  //取得分页桌子变化信息	
	  	private const CMD_RESPONSE_ONLONE_SERVER:String = "REOS";      		//取得所有服务器的在线人数
		private const CMD_RESPONSE_REDBAG:String = "RERB";					//收到红包
		private const CMD_RESPONSE_UPDATE_GOLD:String = "REGB";				//收到金币更新		
		
		private const CMD_RESPONSE_WATCH_ERROR:String = "RESE";   			//收到游戏相关信息
		private const CMD_RESPONSE_FRIEND_CHANGE:String = "NTAF";			//好友信息改变
		private const CMD_RESPONSE_ACTION_FACE:String = "RAAF";				//激活头像结果
		private const CMD_RESPONSE_CHANGE_FACE:String = "CHFCOK";			//更换头像OK
		private const CMD_RESPONSE_SELECT_FACE:String = "RAHD";				//选择头像结果
		private const CMD_RESPONSE_SORT_LIST:String = "RERSL";				//牌桌玩家排名通知		
		private const CMD_RESPONSE_STANDUP_RESULT:String = "REOT";			//站起结果
		//接受的命令(通知)
		private const CMD_NOTIFY_GROUP_INFO:String = "NTGP";				//组分区信息
		private const CMD_NOTIFY_CAN_NOT_TOROOM:String = "RQNI";            //无法进入房间
		private const CMD_NOTIFY_SERVER_ERROR:String = "REMG";            //服务器返回提示信息
		private const CMD_NOTIFY_RESTRICT_LOGIN:String = "NTIP";			//收到服务器拒绝登陆
 		private const CMD_NOTIFY_UPDATAQUEUE:String  = "NTQC";    			//更新队列信息
 		private const CMD_NOTIFY_TIME_TIME:String  = "NTTT";    			//心跳
 		private const CMD_NOTIFY_GM_KICK:String  = "GMSK";    			    //GM踢人
		private const CMD_NOTIFY_SITDOWN_RESULT:String = "REFS";			//收到坐下结果
		private const CMD_NOTIFY_GOLD_CHANGE:String = "NTGC";				//收到桌面钱改变
		private const CMD_NOTIFY_LOW_GOLD:String = "NTPC";					//收到钱不够踢出房间
		
		private const CMD_NOTIFY_STUDY_PRIZE:String = "STOV";				//收到学习教程奖励
		
		private const CMD_NOTIFY_USER_DEL:String = "ULDL";					//收到玩家退出
		private const CMD_NOTIFY_USER_ADD:String = "ULAD";					//收到玩家进入
		
		private const CMD_NOTIFY_INTEGRAL_JIESUAN:String = "REINTE";		//收到积分结算
		
		private const TOURNAMENT_RECV_ADDPOINT_RESULT:String = "TRBURS";	//收到竞技场买点数结果
		
		//登陆送钱
		private const CMD_NOTIFY_TEX_LOGIN_SHOW_DAY_GOLD:String = "SHOWDAYGOLD";	//打开登陆送钱
		private const CMD_NOTIFY_TEX_RECV_LOGIN_GIVE:String = "REDAYGOLD";			//收到登陆送钱的数目
		
		private const CMD_NOTIFY_TEX_RECV_SHOW_FEEDBACK:String = "SHOWFEEDBK"		//收到显示反馈界面
		
		private const CMD_NOTIFY_TEX_SHOW_CHONGZHI:String = "REHISMPAY";				//收到历史最高充值金额
		private const CMD_NOTIFY_TEX_SETTINGS_TXPROPS:String = "TXPROPS";  //道具列表数据
		//-------------
		private var m_guildMemberList:Array = [];
		private var m_deskList:Array = []; //缓存桌子列表
		
		private var m_netptr:IDBufNetwork = null;	//底层网络接口
		private var m_isRequestNum:int = 0;		//喇叭次数
		public function DNetworkGame(net_ptr:IDBufNetwork) 
		{
			this.m_netptr = net_ptr;
			this.m_netptr.addEventListener(DSocketEvent.SYNC, onDataRecv);
		}
		

		private function onDataRecv(e:DSocketEvent):void 
		{
			m_netptr.readbegin();
			var strCmd:String = this.m_netptr.readString();
			trace("DNetworkGame(): 处理指令: " + strCmd);
			var data:Array = [];
			var tmpObj:Object = { };
			var list:Array = [];
			var siteitem:Object = null;
			var len:int = 0;
			var i:int = 0;
			var j:int = 0;
			var n:int = 0;
			
			switch(strCmd)
			{
				//STA########################################################################################
				case CMD_ENTER_ROOM:
				{
					data["nResult"]			= m_netptr.readByte();		//进入结果 1成功，-1失败，-2等级不够 -3金币不够 -4人数满
					data["roomid"]			= m_netptr.readInt();		//房间id
					data["numPeople"]		= m_netptr.readInt();		//房间人数
					data["defaultValue"]	= m_netptr.readInt();		//默認帶入分數
					data["minValue"]		= m_netptr.readInt();		//最小買入分數
					data["maxValue"]		= m_netptr.readInt();		//最大買入分數
						
					dispatchEvent(new DNetworkGameEvent(CMD_ENTER_ROOM, data));
					break;
				}
				case CMD_ROOM_LIST:
				{
					data["len"]				= m_netptr.readInt();		//房间长度
					data["list"] = [];
					for (i = 0; i < data["len"]; i++)
					{
						tmpObj = { };
						tmpObj["id"]		= m_netptr.readInt();			//房间id
						tmpObj["name"]		= m_netptr.readString();		//房间名称
						tmpObj["peilv"]		= m_netptr.readInt();			//房间赔率
						tmpObj["needlevel"]	= m_netptr.readInt();			//需要最小等级
						tmpObj["needgold"]	= m_netptr.readInt();			//最小携带						
						tmpObj["gameid"]	= m_netptr.readInt();			//游戏ID
						tmpObj["numPeople"]	= m_netptr.readInt();			//房間人數
						tmpObj["maxPeople"]	= 100;							//房間人數上限
						data["list"].push(tmpObj);
					}					
					dispatchEvent(new DNetworkGameEvent(CMD_ROOM_LIST, data));
					break;
				}
				case CMD_ROOM_PEOPLE_NUM:
				{					
					data["roomId"]			= m_netptr.readInt();		//房間ID
					data["numPeople"]		= m_netptr.readInt();		//房間人數
					//DTrace.traceex("DHall -> 房間人數 TJDRMNUM", data);
					dispatchEvent(new DNetworkGameEvent(CMD_ROOM_PEOPLE_NUM, data));
					break;
				}
				case CMD_MY_INFO:
				{
					data["userid"] 			= m_netptr.readInt();					
					data["usersex"] 		= m_netptr.readByte();
					data["usernick"] 		= m_netptr.readString();
					data["imgurl"] 			= m_netptr.readString();
					data["gold"] 			= m_netptr.readInt();			
					data["currExp"] 		= m_netptr.readInt();
					data["expLevel"]		= m_netptr.readInt();
					data["needExp"]			= m_netptr.readInt();
					data["giftId"]			= m_netptr.readInt();
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_MY_INFO, data));
					break;
				}
				//收到刷新金币
				case CMD_RESPONSE_UPDATE_GOLD:
				{
					data["gold"] = m_netptr.readInt(); 
					data["canjiuji"] = m_netptr.readByte();  //是否可以领取救济:0不行，1可以
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_UPDATE_GOLD, data));
					break;
				}	
				//END########################################################################################
				
				case CMD_NOTIFY_GROUP_INFO:
				{
					data["groupid"] 		= m_netptr.readInt();
					data["isguildroom"] 	= m_netptr.readInt();
					data["guild_pelv_arr"] 	= [];
					len		 				= m_netptr.readInt();
					for (var k:int = 0; k < len; k++)
					{
						data["guild_pelv_arr"].push(m_netptr.readInt())
					}
					data["guild_pelv_arr"].sort();
					data["at_least_gold"] 	= m_netptr.readInt();
					data["at_most_gold"] 	= m_netptr.readInt();
					data["pay_limit"] 		= m_netptr.readInt();
					data["nocheat"]			= m_netptr.readByte();
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_GROUP_INFO, data));
					break;
				}				
				//收到坐下结果
				case CMD_NOTIFY_SITDOWN_RESULT:
				{
					data["code"] = m_netptr.readInt(); 		//返回码
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_SITDOWN_RESULT, data));
					break;
				}			
				case CMD_LOGIN_RESULT:
				
				{
					data["code"] = m_netptr.readShort();
					data["ostime"] = m_netptr.readString();
					this.dispatchEvent(new DNetworkGameEvent(CMD_LOGIN_RESULT, data));
					break;
				}					
				//收到桌子上所有人的信息
				case CMD_RESPONSE_DESK_USERLIST:
				{
					data["deskno"] 			= m_netptr.readInt();
					data["betgold"] 		= m_netptr.readInt();	//桌面筹码数
					data["usergold"] 		= m_netptr.readInt();	//桌子玩家筹码数
					data["playercount"]  	= m_netptr.readByte();  //在玩人数
					data["watchercount"] 	= m_netptr.readInt();   //观战人数
					data["userlist"] = [];
					n = m_netptr.readByte();		//桌内人数
					for (i = 0; i < n; i++)
					{
						data["userlist"][i] = [];
						data["userlist"][i]["state_value"]	= m_netptr.readByte();		//每个座位的状态 SITE_UI_VALUE = _S{NULL = 0, NOTREADY = 1, READY = 2, PLAYING = 3}
						data["userlist"][i]["userid"]		= m_netptr.readInt();		//ID
						data["userlist"][i]["nick"]			= m_netptr.readString();	//昵称
						data["userlist"][i]["isvip"]		= m_netptr.readByte();		//是否VIP玩家:0不是，1是
						data["userlist"][i]["faceurl"]		= m_netptr.readString();	//头像
						data["userlist"][i]["gold"]			= m_netptr.readInt();		//金币
						data["userlist"][i]["role"]         = m_netptr.readInt();       //频道角色
						data["userlist"][i]["sex"]          = m_netptr.readInt();       //性别
						data["userlist"][i]["dhome_status"] = m_netptr.readInt();       //家园标识
					}
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_DESK_USERLIST, data));
					break;
				}
				case CMD_RESPONSE_ROOMLIST_DESK_CHANGED:
				{
					n = m_netptr.readInt();
					for (i = 0 ; i < n; i++ )
					{ 
						list[i] = new Object();
						list[i]["deskno"] 		= m_netptr.readInt();		//桌号
						list[i]["name"] 		= m_netptr.readString();	//名称
						list[i]["desktype"] 	= m_netptr.readByte();		//类型:1普通，2比赛，3VIP专用
						list[i]["fast"] 		= m_netptr.readByte();		//是否快速
						list[i]["betgold"] 		= m_netptr.readInt();		//桌面筹码数
						list[i]["usergold"] 	= m_netptr.readInt();		//桌子玩家筹码数
						list[i]["needlevel"] 	= m_netptr.readInt();		//桌子解锁等级				
						list[i]["smallbet"] 	= m_netptr.readInt();		//小盲
						list[i]["largebet"] 	= m_netptr.readInt();		//大盲						
						list[i]["at_least_gold"] = m_netptr.readInt();		//金币下限 报名费
						list[i]["at_most_gold"]  = m_netptr.readInt();		//金币上限						
						list[i]["specal_choushui"] = m_netptr.readInt();	//抽水
						list[i]["min_playercount"] = m_netptr.readByte();	//最少开局人数
						list[i]["max_playercount"] = m_netptr.readByte();	//最多开局人数
						list[i]["playercount"] 	= m_netptr.readByte();		//当前在玩人数
						list[i]["watchercount"] = m_netptr.readInt();	    //观战人数
						list[i]["start"] 		= m_netptr.readByte();		//是否开始 1=是 0=开始
						list[i]["sitecount"]	= m_netptr.readByte();		//凳子数
						list[i]["siteinfo"]		= [];
						for (j = 0; j < list[i]["sitecount"]; j++)
						{
							siteitem = new Object();
							siteitem["state_value"]	= m_netptr.readByte();		//每个座位的状态 SITE_UI_VALUE = _S{NULL = 0, NOTREADY = 1, READY = 2, PLAYING = 3}
							siteitem["userid"]		= m_netptr.readInt();		//
							siteitem["nick"]		= m_netptr.readString();	//
							siteitem["faceurl"]		= m_netptr.readString();	//
							list[i]["siteinfo"][j] = siteitem;
						}
					}
					data.list = list;
					data.page = m_netptr.readShort();						//当前页
					data.totalpage = m_netptr.readShort();					//共多少页
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_CURPAGEROOM_CHANGED, data));
					break;
				}				
				case CMD_NOTIFY_UPDATAQUEUE:
				{	
					data["queueplayer"] = m_netptr.readInt();
//					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_QUEUE_INFO,data));
					break;					
				}
				
				//收到服务器返回错误提示:0xx大厅的，1xx游戏里的
				case CMD_NOTIFY_SERVER_ERROR:
				{
					data["msgtype"] 	= m_netptr.readByte(); 
					data["msg"] 		= m_netptr.readString(); 
					if(data["msgtype"] == 0)
					{
						this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_SERVER_ERROR, data));
					}
					break;
				}
				//服务器IP限制登陆
				case CMD_NOTIFY_RESTRICT_LOGIN:
				{
					data["retcode"] 	= m_netptr.readInt(); //是否可以登录
					data["msg"] 		= m_netptr.readString(); //返回消息
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_RESTRICT_LOGIN, data));
					break;
				}
				
				//收到学习教程奖励
				case CMD_NOTIFY_STUDY_PRIZE:
				{
					data["userid"] 		= m_netptr.readInt(); 
					data["addgold"] 	= m_netptr.readInt(); 
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_STUDY_PRIZE, data));
					break;
				}				
				
				case CMD_NOTIFY_CAN_NOT_TOROOM:
				{
					 data["IntoRoomStats"] 	= m_netptr.readByte(); 
					 data["gold"] 			= m_netptr.readInt(); 
					 this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_CAN_NOT_TOROOM, data));
					 break;
				}
				//GM踢人
				case CMD_NOTIFY_GM_KICK:
				{
					 data["code"] = m_netptr.readInt(); 
					 this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_GM_KICK, data));
					 break;
				}				
				//心跳
				case CMD_NOTIFY_TIME_TIME:
				{
					sendReplyTimeTime();
					break;
				}
				//在线人数
				case CMD_RESPONSE_ONLONE_SERVER:
				{
					var groupid:String = ""; 
					while ((groupid = m_netptr.readString())!= "")
					{
						data[groupid] = m_netptr.readInt();		//在线人数
					}
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_ONLINE_SERVER, data));
					break;
				}
				//收到观战失败
				case CMD_RESPONSE_WATCH_ERROR:
				{
					data["errorcode"]		= m_netptr.readByte();
					
					if (data["errorcode"] == -2)
					{
						data["userid"]		= m_netptr.readInt();
						data["roomid"]		= m_netptr.readInt();
 					}
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_WATCH_ERROR, data));
					break;
					
				}
				//收到刷新金币
				case CMD_NOTIFY_GOLD_CHANGE:
				{
					data["site"] = m_netptr.readInt(); 				//座位号
					data["gold"] = m_netptr.readInt(); 				//新钱
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_CHANGE_GOLD, data));
					break;
				}			
				//收到金币太多(少)，踢出房间
				case CMD_NOTIFY_LOW_GOLD:
				{
					data["retcode"] = m_netptr.readInt(); 				//返回码
					data["gold"] = m_netptr.readInt(); 				//钱限制
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_LOW_GOLD, data));
					break;
				}			
				//收到玩家进入
				case CMD_NOTIFY_USER_ADD:
				{
					data["userid"] = m_netptr.readInt();      //用户的数据库ID
					data["nick"] = m_netptr.readString();     //昵称
					data["faceurl"] = m_netptr.readString();  //头像url
					data["gold"] = m_netptr.readInt();        //金币数目
					data["exp"] = m_netptr.readInt();         //经验值
					data["prestige"] = m_netptr.readInt();    //声望
					data["integral"] = m_netptr.readInt();    //荣誉
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_USER_ADD, data));
					break;
				}
				//收到玩家退出
				case CMD_NOTIFY_USER_DEL:
				{
					data["userid"] = m_netptr.readInt();
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_USER_DEL, data));
					break;
				}
				//收到积分结算
				case CMD_NOTIFY_INTEGRAL_JIESUAN:
				{
					data["all"] = m_netptr.readInt();
					data["normal"] = m_netptr.readInt();
					data["extra"] = m_netptr.readInt();
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_INTEGRAL_JIESUAN, data));
					break;
				}
				//竞技场买点数结果
				case TOURNAMENT_RECV_ADDPOINT_RESULT:
				{
					data["result"] = m_netptr.readInt();
					data["newpoint"] = m_netptr.readInt();
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_TOUR_ADDPOINT_RESULT, data));
					break;
				}
				//激活头像结果
				case CMD_RESPONSE_ACTION_FACE:
				{
					data["success"] = m_netptr.readInt();
					data["faceid"] = m_netptr.readInt();
					data["price"] = m_netptr.readInt();
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_ACTIVE_FACE, data));
					break;
				}
				case CMD_RESPONSE_CHANGE_FACE:
				{
					data["face"] = m_netptr.readString();
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_CHANGE_FACE_OK, data));
					break;
				}
				case CMD_RESPONSE_SELECT_FACE:
				{
					data["notshowextra"] = m_netptr.readInt();
					data["extrafacenum"] = m_netptr.readInt();
					data["extrafaces"] = new Array();					
					for (i = 0; i < data["extrafacenum"]; i++)
					{
						data["extrafaces"][i] = m_netptr.readInt();
					}
					data["vipfacenum"] = m_netptr.readInt();
					data["vipfaces"] = new Array();
					for (i = 0; i < data["vipfacenum"]; i++)
					{
						data["vipfaces"][i] = m_netptr.readInt();												
					}					
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_SELECT_FACE_OK, data));
					break;
				}						
				//用户排名列表
				case CMD_RESPONSE_SORT_LIST:
				{
					trace("收到客户端请求房间玩家排名")
					data["type"] = m_netptr.readString();
					var listdata:Array = [];
					len = m_netptr.readShort();
					for (i = 0; i < len; i++)
					{
						var item:Object = { };
						item["userid"] = m_netptr.readInt();      //用户的数据库ID
						item["nick"] = m_netptr.readString();     //昵称
						item["faceurl"] = m_netptr.readString();  //头像url
						item["gold"] = m_netptr.readInt();        //金币数目
						item["exp"] = m_netptr.readInt();         //经验值
						item["prestige"] = m_netptr.readInt();    //声望
						item["integral"] = m_netptr.readInt();    //荣誉
						//.....
						//...
						listdata.push(item);
					}
					data["listdata"] = listdata;
					trace("收到来自服务器的玩家排名数据....");
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_SORT_LIST, data));
					break;
				}
				//收到站起结果
				case CMD_RESPONSE_STANDUP_RESULT:
				{
					data["success"] 			= m_netptr.readShort();			//结果
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_STAND_UP_RESULT, data));
					break;
				}				
				case CMD_NOTIFY_TEX_BBS_URL:
				{					
					data["BBSURL"]		= m_netptr.readString();		//BBS验证串
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_TEX_RECV_BBS_URL, data));
					break;
				}
				case CMD_NOTIFY_TEX_LOGIN_SHOW_DAY_GOLD:
				{
					data["result"]		= m_netptr.readInt();  //-1，IP超限，1成功，其他未知错误
					data["maxviplevel"] = m_netptr.readInt();      //最高VIP等级
					data["vipadd"] 	= m_netptr.readInt();      //vip金币加成
					//DTrace.traceex("CMD_NOTIFY_TEX_LOGIN_SHOW_DAY_GOLD:", data);
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_TEX_LOGIN_SHOW_DAY_GOLD, data));
					break;
				}
				case CMD_NOTIFY_TEX_RECV_LOGIN_GIVE:
				{
					data["success"] = m_netptr.readByte();
					data["gold"] = m_netptr.readInt();  //本身领到的筹码500
					data["vipadd"] = m_netptr.readInt();  //vip加成888，1888，3888
					data["charmlevel"] = m_netptr.readInt(); //农场魅力等级
					data["charmadd"] = m_netptr.readInt(); //农场魅力加成
					data["vtask_add"] = m_netptr.readInt(); //V任务赠送筹码
					//DTrace.traceex("CMD_NOTIFY_TEX_RECV_LOGIN_GIVE:", data);
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_TEX_RECV_LOGIN_GIVE, data));
					break;
				}
				case CMD_NOTIFY_TEX_RECV_SHOW_FEEDBACK:
				{
					data["nFlag"] = m_netptr.readByte();  //是否反馈：0, 不能用反馈；1：可以用反馈
					//DTrace.traceex("CMD_NOTIFY_TEX_RECV_SHOW_FEEDBACK:", data);
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_TEX_RECV_FEEDBACK_CAN_USE, data));
					break;
				}
				case CMD_NOTIFY_TEX_SHOW_CHONGZHI:
				{
					data["history_maxpay"] = m_netptr.readInt();   //历史最高的单次充值金额
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_TEX_RECV_SHOW_CHONGZHI, data));
					break;
				}
				case CMD_NOTIFY_TEX_PRIVILEGE_YANZHENG:
				{
					data["checkRs"] = m_netptr.readByte();
					data["checkMsg"] = m_netptr.readString();
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_TEX_RECV_PRIVILEGE_CHECK, data));
					//this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_TEX_RECV_PRIVILEGE_CHECK, data));
					break;
				}
				case CMD_TEX_CHOOSE_ROLE:
				{
					
					data["isShow"] 	= m_netptr.readByte();
					data["sex"] 	= m_netptr.readByte();
					data["nick"] 	= m_netptr.readString();
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_CHOOSE_SHOW, data));
					break;
				}
				//-------------------小喇叭str------------------------
				case CMD_TEX_SPEAKER_NUM:
				{
					data["speakerNum"] = m_netptr.readInt();
					data["isRequestNum"] = m_isRequestNum;
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_SPEAKER_NUM, data));
					break;
				}
				case CMD_TEX_SPEAKER_BROADCAST:
				{
					data["isSucc"] = m_netptr.readByte();  //是否成功:  0,失败; 1:成功
					data["content"] = m_netptr.readString();
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_SPEAKER_BROADCAST, data));
					break;
				}
				//-------------------小喇叭end------------------------
				case CMD_TEX_UPDATE_NICK_INFO:
				{
					data["isSucc"] = m_netptr.readByte();  //是否成功:  0,失败; 1:成功
					data["reason"] = m_netptr.readString(); //失败原因
					data["nick"]   = m_netptr.readString();//用户昵称
					data["sex"]   = m_netptr.readByte();//用户性别
					data["face"]   = m_netptr.readString();//用户头像
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_UPDATE_NICK_INFO, data));
					break;
				}
				//-------------------异地上线保护str------------------------
				case CMD_TEX_CHECK_IP:
				{
//					DTrace.traceex("收到是否弹出异地上线保护对话－－－－－－－－－－－");
					data["isSucc"] = m_netptr.readByte(); //是否弹出“异地上线保护”窗口：0，不弹；1：弹出
					data["isFirst"] = m_netptr.readByte();//是否第一次设置登录保护: 0,表示不是第一次设置；1，表示是第一次设置
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_CHECK_IP, data));
					break;
				}
				case CMD_TEX_UNLOCK:
				{
					data["isSucc"] = m_netptr.readByte();//解锁是否成功: 0，表示解锁不功能；1，表示解锁成功
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_UNLOCK,data));
					break;
				}
				//-------------------异地上线保护end------------------------
				//-------------------游戏设置str----------------------------
				case CMD_TEX_TXPERSZ:
				{
					data["isSameName"] = m_netptr.readByte();//设置结果：（-1，表示昵称重名了；0，表示设置不成功；1，表示设置成功）
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_TXPERSZ, data));
					break;
				}
				//case CMD_TEX_TXPAYSZ:
				//{
					//data["isSucc"] = m_netptr.readByte();//设置结果：（0，表示设置不成功；1，表示设置成功）
					//this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_TXPAYSZ, data));
					//break;
				//}				
				//-------------------游戏设置end----------------------------
				//收到更新游戏道具数量
				case CMD_RECV_REFRESH_PROPS_COUNT:
				{					
					data["props_id"] = m_netptr.readInt();		//道具ID
					data["props_count"] = m_netptr.readInt();	//道具数量
					this.dispatchEvent(new DNetworkGameEvent(DNetworkGameEvent.ON_RECV_REFRESH_PROPS_COUNT, data));
					break;
				}
				default:
				{
					//DTrace.traceex("!!!DNetworkGame: 发现未处理指令: " + strCmd);
					break;
				}
			}
		}
		
		/* INTERFACE hall.hall.net_common.IDNetworkGame */
		
		//STA########################################################################################
		/**
		 * 请求进入游戏
		 * @param	roomid
		 */
		public function requestEnterRoom(roomid:int):void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_ENTER_ROOM);
			m_netptr.writeInt(roomid);
			m_netptr.writeEnd();
		}
		
		/**
		 * 发送请求房间列表
		 */
		public function requestRoominfo():void
		{
			
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_ROOM_LIST);
			m_netptr.writeEnd();
		}
		
		//END########################################################################################
		/**
		 * 发送请求游戏服务器登录
		 * @param	strUsername
		 * @param	strPassword
		 */
		public function sendRequestLoginGame(userRealId:int, strPassword:String):void
		{
			
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_REQUEST_LOGIN);
			m_netptr.writeInt(userRealId);
			m_netptr.writeString(strPassword);
			m_netptr.writeByte(DConfig.nRegSit);		//from YY
			m_netptr.writeString(DConfig.strLoginType);
			m_netptr.writeEnd();
		}
		
	
		
		/**
		 * 发送请求房间下一页
		 */	
		public function sendRequestPage(page:int,pagesize:int, hidenull:int, hidefull:int):void
		{
			//这个函数已经废弃不用
			return;
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_REQUEST_ROOMLIST_PAGE);
			m_netptr.writeShort(page);
			m_netptr.writeShort(pagesize);
			m_netptr.writeByte(hidenull);
			m_netptr.writeByte(hidefull);
			m_netptr.writeEnd();
		}
		
		/**
		 * 请求桌子的玩家列表
		 */	
		public function sendRequestDeskUser(deskno:int):void
		{
			m_netptr.writeBegin();
			m_netptr.writeString("SDDU");
			m_netptr.writeInt(deskno);
			m_netptr.writeEnd();
		}
		
		public function sendRequestStandup():void
		{
			//DTrace.traceex("发送自己站起来,sendRequestStandup()");
			m_netptr.writeBegin();
			m_netptr.writeString("RQSU");
			m_netptr.writeEnd();
		}
		
		public function sendRequestActiveExtraFace(faceurl:String, sure:int):void
		{
			//DTrace.traceex("发送激活头像");
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_REQUEST_ACTIVE_FACE);
			m_netptr.writeString(faceurl);
			m_netptr.writeInt(sure);
			m_netptr.writeEnd();
		}
		/*
		 * 发送离开牌桌大厅
		 */
		public function sendClientLeaveRoom():void
		{
			//DTrace.traceex("sendClientLeaveRoom()");
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_REQUEST_CLIENT_LEAVE_ROOM);
			m_netptr.writeEnd();
		}		
		
		public function sendRequestChangeFace(faceUrl:String):void
		{
			//DTrace.traceex("发送改变头像");
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_REQUEST_CHANGE_FACE);
			m_netptr.writeString(faceUrl);
			m_netptr.writeEnd();
		}		
		
		private function sendReplyTimeTime():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_REQUEST_TIME_TIME);			
			m_netptr.writeEnd();
		}		
		
		//查选所有服务器的在线人数
		public function sendRequestOnlinePlayerCountAllServer():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_REQUEST_ONLONE_SERVER);			
			m_netptr.writeEnd();			
		}
		
		//请求服务器送钱
		public function sendRequestGiveGold():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_REQUEST_GIVE_GOLD);			
			m_netptr.writeEnd();
		}		
	
		
		//请求服务器刷新钱
		public function sendUpdateGold():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_REQUEST_UPDATE_GOLD);
			m_netptr.writeEnd();
		}		
		
		public function sendUpdateVipInfo():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_REQUEST_UPDATE_VIPINFO);
			m_netptr.writeEnd();
		}
		//发送请求论坛字串
		public function sendRequestURL():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_NOTIFY_TEX_BBS_URL);
			m_netptr.writeEnd();
		}
		/**
		 * 用户请求观战
		 */
		public function sendRequestWatch(deskno:int):void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_REQUEST_WATCH);
			m_netptr.writeInt(deskno);
			m_netptr.writeEnd();
		}
		
		/**
		 * 用户请求退出观战
		 */
		public function sendRequestExitWatch():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_REQUEST_EXIT_WATCH);
			m_netptr.writeEnd();
		}
		
		/**
		 * 客户端请求房间玩家排名
		 */
		public function sendRequestRoomSortList(strType:String):void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_REQUEST_ROOM_SORT_LIST);
			m_netptr.writeString(strType);
			m_netptr.writeEnd();
		}		
		
		/**
		 * 客户端请求房间全部玩家列表
		 */
		public function sendRequestRoomUserList():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString("RQASL");
			m_netptr.writeEnd();
		}	
		
		/**
		 * 发送离开游戏
		 */
		public function sendExitGame():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString("RQUL");
			m_netptr.writeEnd();
		}	
		
		/**
		 * 发送选择游戏
		 */
		public function sendSelectedGame():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString("RQUE");
			m_netptr.writeEnd();
		}	
		
		//发送选头像
		public function sendRequestSelectFace():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString("RAHD");
			m_netptr.writeEnd();
		}
		
		//发送看完教程
		public function sendStudyOver():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString("STOV");
			m_netptr.writeEnd();
		}
		
		//发送领取救济
		public function sendRequestGiveChouMa():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString("RQGIVE");
			m_netptr.writeEnd();
		}
		
		/* INTERFACE hall.hall.net_common.IDNetworkGame */		
		public function sendSitDown(deskno:int, siteno:int, peilv:int):void
		{
			m_netptr.writeBegin();
			m_netptr.writeString("RQSD");
			m_netptr.writeInt(deskno);
			m_netptr.writeInt(siteno);
			m_netptr.writeInt(peilv);
			m_netptr.writeEnd();		
		}
		
		public function tour_sendBuyPoint():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString("TRBUGD");
			m_netptr.writeEnd();	
		}
		
		public function sendRequestLoginLingQu():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString("RQDAYGOLD");
			m_netptr.writeEnd();
		}
		
		public function sendRequestFeedBack():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString("SHOWFEEDBK");
			m_netptr.writeEnd();
		}
		
		public function sendRequestShowChongzhi():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_NOTIFY_TEX_SHOW_CHONGZHI);
			m_netptr.writeEnd();
		}
		
		//-------------------特权码str------------------------
		public function sendRequestPrivilegeCheck(code:String):void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_NOTIFY_TEX_PRIVILEGE_YANZHENG);
			m_netptr.writeString(code);
			m_netptr.writeEnd();
		}
		//-------------------特权码end------------------------
		
		public function sendRequestUpdateUserChannelInfo(userInfo:Array):void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_TEX_UPDATE_NICK_INFO);
			m_netptr.writeString(userInfo['nick']);
			m_netptr.writeInt(userInfo['sex']);
			//m_netptr.writeString(DConfig.strChannelId);
			m_netptr.writeEnd();
		}
		//-------------------小喇叭str------------------------
		public function sendRequestBroadcast(broadcastContent:String):void
		{  
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_TEX_SPEAKER_BROADCAST);
			m_netptr.writeString(broadcastContent);
			m_netptr.writeEnd();
		}
		public function sendRequestSpeakerNum(isRequestNum:int = 0):void
		{
			m_isRequestNum = isRequestNum;
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_TEX_SPEAKER_NUM);
			m_netptr.writeEnd();
		}
		//-------------------小喇叭end------------------------
		//-------------------异地上线保护str------------------------
		public function sendRequestCheckIp():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_TEX_CHECK_IP);
			m_netptr.writeEnd();
			//测试代码
			//var data:Array = [];
			//data["isSucc"] = 1;   //1表示弹窗，0表示不弹
			//data["isFirst"] = 1;  //1表示第一次设置，0表示不是第一次设置
			//this.dispatchEvent(new  DNetworkGameEvent("ON_RECV_CHECK_IP", data));
			//DTrace.traceex("请求是否弹出异地上线保护对话－－－－－－－－－－－");
		}
		public function sendRequestUnlock(pwd:String):void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_TEX_UNLOCK);
			m_netptr.writeString(pwd);
			m_netptr.writeEnd();
			//测试代码
			//var data:Array = [];
			//data["isSucc"] = 1;
			//this.dispatchEvent(new  DNetworkGameEvent("ON_RECV_UNLOCK", data));
		}
		//-------------------异地上线保护end------------------------
		//-------------------游戏设置str----------------------------
		public function sendRequestPersonalSettings(nikeName:String ,sex:int,privilege:int, chat:int):void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_TEX_TXPERSZ);
			m_netptr.writeString(nikeName);
			m_netptr.writeByte(sex);
			m_netptr.writeByte(privilege);
			m_netptr.writeByte(chat);
			m_netptr.writeEnd();
			//测试代码
			//var data:Array = [];
			//data['isSameName'] = -1;
			//this.dispatchEvent(new DNetworkGameEvent("ON_RECV_TXPERSZ",data));
		}
		public function sendRequestPropsList():void
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_NOTIFY_TEX_SETTINGS_TXPROPS);
			m_netptr.writeEnd();
		}
		
		public function requestBackToHall():void 
		{
			m_netptr.writeBegin();
			m_netptr.writeString(CMD_BACK_TO_HALL);
			m_netptr.writeEnd();
		}
		//牌样设置
		//public function sendRequestPokeSettings(cards:int,cardBack:int):void
		//{
			//m_netptr.writeBegin();
			//m_netptr.writeString(CMD_TEX_TXPAYSZ);
			//m_netptr.writeByte(cards);
			//m_netptr.writeByte(cardBack);
			//m_netptr.writeEnd();
		//}
		//-------------------游戏设置end----------------------------
	}
}